INCLUDE = -I./base -I./open -I./tool -I../../../../../xsp -I../../../../../cae
LIBPATH = ../../../../../build/static_vsproj/debug
CFLAG = -g -fPIC -D__posix $(INCLUDE) -DMONGO_HAVE_STDINT
LFLAG = -L./ -L$(LIBPATH)
LLIBS = -lcppcgi -lcae -lxsp -lcrypto -lrt

INSTALL_PATH = ../../release

CGIS = test.cgi \
	sadmr.cgi license.cgi sver.cgi upserv.cgi blacklist.cgi whitelist.cgi \
	group.cgi grdsrv2.cgi grdsrv5.cgi gwlsrv.cgi gwlsecu.cgi \
	dap.cgi dsta.cgi usrinfo.cgi role.cgi rcontrl.cgi rtime.cgi rspace.cgi raccess.cgi rule.cgi \
	position.cgi ainfo.cgi log.cgi login.cgi exit.cgi onlyname.cgi username.cgi \
	radius.cgi portal.cgi portal_ad.cgi

all: libcppcgi.so $(CGIS)
	cd interface && make;
	@echo =========================================================================================

install:
	cp $(LIBPATH)/*.so libcppcgi.so $(INSTALL_PATH)/lib;
	cp *.cgi $(INSTALL_PATH)/www/cgi-bin;

libcppcgi.so: base/cgi.o open/md5.o open/base64.o tool/connect.o tool/init.o
	$(CXX) -shared -fPIC -o libcppcgi.so $^ -m elf_i386 -m32

base/%.o: base/%.cpp
	$(CXX) $(CFLAG) -c -o $@ $^ -m32

open/%.o: open/%.cpp
	$(CXX) $(CFLAG) -c -o $@ $^ -m32

tool/%.o: tool/%.cpp
	$(CXX) $(CFLAG) -c -o $@ $^ -m32

%.cgi: wac/%.o
	$(CXX) $(LFLAG) -o $@ $^ $(LLIBS) -m elf_i386 -m32

wac/%.o: wac/%.cpp
	$(CXX) $(CFLAG) -c -o $@ $^ -m32

clean:
	-rm base/*.o;
	-rm open/*.o;
	-rm tool/*.o;
	-rm *.cgi;
	-rm libcppcgi.so;
	-rm load_ifconf;
	cd interface && make clean;
	@echo =========================================================================================
